package com.xiaoKe.zhonghzu.global.base;

/**
 * @ProjectName : xiaoke-pad-zhongzhu
 * @Author : Shijingna
 * @Time : 2024/8/1 14:28
 * @Description : 文件描述
 */
import android.content.Context;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;



public class CustomGridLayoutManager extends GridLayoutManager {

    private int numColumns;
    public CustomGridLayoutManager(Context context, int spanCount  ) {
        super(context, spanCount);
        this.numColumns = spanCount;
    }

    @Override
    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
        super.onLayoutChildren(recycler, state);

        if (state.getItemCount() > 0) {
            int width = getWidth();
            int itemWidth = (width - getPaddingLeft() - getPaddingRight()) / numColumns;
            setSpanSizeLookup(new SpanSizeLookup() {
                @Override
                public int getSpanSize(int position) {
                    // This will make each item span one column.
                    return 1;
                }
            });


        }
    }
}
